home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 14.5 KB | 501 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UQD3DViewerView.cp
- // Copyright © 1996 by Geoffrey J. Clapp. All rights reserved.
- //----------------------------------------------------------------------------------------
-
-
- #ifndef __UQD3DViewer__
- #include "UQD3DViewer.h"
- #endif
-
- //MacApp
- #if qDrag
-
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
-
- #endif
-
- //QuickDraw3D
- #ifndef QD3DViewer_h
- #include "QD3DViewer.h"
- #endif
-
- #ifndef QD3DView_h
- #include "QD3DView.h" //for rendering services
- #endif
-
- //========================================================================================
- // Global Initialization Procedure
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUQD3DViewerView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUQD3DViewerView()
- {
- // So the linker doesn't dead strip class info
- MA_REGISTER_CLASS(TQD3DViewerView);
-
- #if qDebug
- #if qDrag
- if(!HasDragManager())
- DebugStr("\p Due to a bug in QD3D (1.0.3), the viewer will crash without the DragManager installed.");
- #endif
- #endif
- } // InitUQD3DViewerView
-
- //========================================================================================
- // CLASS TQD3DViewerView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment AOpen
- MA_DEFINE_CLASS_M1(TQD3DViewerView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- TQD3DViewerView::TQD3DViewerView() :
- fViewer(NULL),
- fUseManualCreation(FALSE)
- {
- } // TQD3DViewerView::TQD3DViewerView
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TQD3DViewerView::~TQD3DViewerView()
- {
- this->RemoveViewerFromView();
- }// TQD3DViewerView destructor
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::IQD3DViewerView:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TQD3DViewerView::IQD3DViewerView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize)
- {
- this->IView(itsDocument,itsSuperView,itsLocation,itsSize, sizeFixed, sizeFixed);
- } // TQD3DViewerView::IQD3DViewerView
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::Draw(const VRect& area)
- {
-
- Inherited::Draw(area);
-
- if(fViewer)
- {
- this->GetWindow()->Focus();
- Q3ViewerDraw(fViewer);
- this->Focus();
- }
-
- } // TQD3DViewerView::Draw
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment AOpen
-
- void TQD3DViewerView::DoPostCreate(TDocument* itsDocument)
- {
- Inherited::DoPostCreate(itsDocument);
-
- if(!fUseManualCreation)
- this->AddViewerToView(kQ3ViewerDefault);
-
- } // TQD3DViewerView::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::DoSetupMenus()
- {
- Inherited::DoSetupMenus();
-
- //The base class will handle cut, copy, paste and clear.
-
- if(fViewer)
- {
- Boolean hasImage = FALSE;
-
- if(Q3ViewerGetState(fViewer) == kQ3ViewerHasModel)
- hasImage = TRUE;
-
- Enable(cCut, hasImage);
- Enable(cCopy, hasImage);
- gClipboardMgr->CanPaste('3DMF'); //can paste a 3DMF file
- Enable(cClear, hasImage);
- }
-
- } // TQD3DViewerView::DoSetupMenus
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TQD3DViewerView::DoMenuCommand(CommandNumber aCommandNumber)
- {
- switch (aCommandNumber)
- {
- //will do these as undo-able commands, but for now will just do the quick away.
-
- case cCut:
- Q3ViewerCut(fViewer);
- break;
-
- case cCopy:
- Q3ViewerCopy(fViewer);
- break;
-
- case cPaste:
- Q3ViewerPaste(fViewer);
- break;
-
- case cClear:
- Q3ViewerClear(fViewer);
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TQD3DViewerView::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
-
- void TQD3DViewerView::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- Boolean handledEvent = FALSE;
-
- if (fViewer)
- {
- this->GetWindow()->Focus();
- handledEvent = Q3ViewerEvent(fViewer, &(event->fEventRecord));
- this->Focus();
- }
-
- //Pass the event off to MacApp if QD3D did not handle it
- if (!handledEvent)
- Inherited::DoMouseCommand(theMouse,event,hysteresis);
-
- } // TQD3DViewerView::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::AddViewerToView:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::AddViewerToView(unsigned long theViewerFlags)
- {
- VRect theFrame;
- this->GetFrame(theFrame);
- //inset to keep frame adorners, etc., if any
- VPoint thePoint(1,1);
- theFrame.Inset(thePoint);
- CRect theCRectFrame = theFrame.ToRect();
-
- GrafPtr theWindowPort = this->GetWindow()->GetGrafPort();
-
- fViewer = Q3ViewerNew((CGrafPtr)theWindowPort,theCRectFrame,theViewerFlags);
-
- } // TQD3DViewerView::AddViewerToView
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::RemoveViewerFromView:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::RemoveViewerFromView()
- {
- if(fViewer)
- FailOSErr(Q3ViewerDispose(fViewer));
- } // TQD3DViewerView::RemoveViewerFromView
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetRenderer:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetRenderer(TQ3ObjectType renderType, Boolean redraw)
- {
-
- TQ3ViewObject theView = Q3ViewerGetView(fViewer);
- TQ3Status the3DStatus = Q3View_SetRendererByType(theView, renderType);
-
- if (the3DStatus != kQ3Success )
- {
- Q3Object_Dispose(theView) ; //this should undo anything we may have messed
- //up trying to set the render
- Failure(0,0);//••• need better error handling
- }
-
- if(redraw)
- this->ForceRedraw();
- } // TQD3DViewerView::SetRenderer
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::GetRenderer:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TQ3RendererObject* TQD3DViewerView::GetRenderer()
- {
- TQ3RendererObject* theRenderer = NULL;
-
- if(fViewer)
- {
- TQ3ViewObject theView = Q3ViewerGetView(fViewer);
- TQ3Status the3DStatus = Q3View_GetRenderer(theView,theRenderer);
-
- if (the3DStatus != kQ3Success )
- {
- Q3Object_Dispose(theView) ; //this should undo anything we may have messed
- //up trying to get the render
- Failure(0,0); //•••clean this up later
-
- }
- }
- #if qDebug
- else
- {
- DebugStr("\p Attempted to GetRenderer without a viewer object.");
- }
- #endif
- return theRenderer;
- } // TQD3DViewerView::GetRenderer
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::AsPict:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- PicHandle TQD3DViewerView::AsPict()
- {
- PicHandle thePicHandle = NULL;
-
- if(fViewer)
- {
- thePicHandle = Q3ViewerGetPict(fViewer);
- //•••need error case code. What if it failed?
- }
- #if qDebug
- else
- {
- DebugStr("\p Attempted to get a Pict without a viewer object.");
- }
- #endif
-
- return thePicHandle;
- } // TQD3DViewerView::AsPict()
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetBackgroundColor:
- /*
- Note: QuickDraw3D uses it's own color structures. When calling this method, if you have
- an RGB value handy that you want to use (maybe you called GetColor), the best thing
- to do is to get each value from your RGB.x, divide it by 65535, and stuff it back in
- the TQ3ColorARGB structure.
-
- Or, you can just use the easy overloaded version of this function...
-
- */
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetBackgroundColor(TQ3ColorARGB* newColor,Boolean redraw)
- {
-
- FailOSErr(Q3ViewerSetBackgroundColor(fViewer,newColor));
- if(redraw)
- this->Update();
-
- } // TQD3DViewerView::SetBackgroundColor()
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetBackgroundColor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetBackgroundColor(RGBColor newColor, float alpha, Boolean redraw)
- {
- TQ3ColorARGB theQ3Color;
- float maxColor = 65535.0;
-
- theQ3Color.r = newColor.red/maxColor;
- theQ3Color.g = newColor.green/maxColor;
- theQ3Color.b = newColor.blue/maxColor;
-
- theQ3Color.a = alpha;
-
- this->SetBackgroundColor(&theQ3Color,redraw);
-
- } // TQD3DViewerView::SetBackgroundColor()
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::GetRGBBackgroundColor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- RGBColor TQD3DViewerView::GetRGBBackgroundColor()
- {
- RGBColor theRGBColor;
- TQ3ColorARGB theQ3Color;
-
- FailOSErr(Q3ViewerGetBackgroundColor(fViewer,&theQ3Color));
-
- float maxColor = 65535.0;
-
- theRGBColor.red = theQ3Color.r * maxColor;
- theRGBColor.green = theQ3Color.g * maxColor;
- theRGBColor.blue = theQ3Color.b * maxColor;
-
- return theRGBColor;
-
- } // TQD3DViewerView::GetRGBBackgroundColor()
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::GetBackgroundColor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- TQ3ColorARGB* TQD3DViewerView::GetBackgroundColor()
- {
- TQ3ColorARGB* theQ3Color = NULL;
-
- FailOSErr(Q3ViewerGetBackgroundColor(fViewer,theQ3Color));
-
- return theQ3Color;
-
- } // TQD3DViewerView::GetBackgroundColor()
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::DoSetCursor:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::DoSetCursor(const VPoint& localPoint,
- RgnHandle cursorRegion)
- {
- //•••Needs to be fixed - does not work right, and the localpoint needs to be
- //in window coor, not view coords.
- CPoint localQDPoint;
- localQDPoint = this->ViewToQDPt(localPoint);
-
- Boolean handled = Q3ViewerAdjustCursor(this->fViewer,localQDPoint);
-
- if(!handled)
- TView::DoSetCursor(localPoint,cursorRegion);
-
- } // TQD3DViewerView::SetCreationType
-
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetCreationType:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetCreationType(Boolean UseManual)
- {
- fUseManualCreation = UseManual;
- } // TQD3DViewerView::SetCreationType
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetViewerFlags:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetViewerFlags(unsigned long theViewerFlags)
- {
- FailOSErr(Q3ViewerSetFlags(fViewer,theViewerFlags));
- } // TQD3DViewerView::SetViewerFlags
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::GetViewerFlags:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- unsigned long TQD3DViewerView::GetViewerFlags()
- {
- unsigned long theFlags;
-
- if(fViewer)
- {
- theFlags = Q3ViewerGetFlags(fViewer);
- }
- else
- {
- #if qDebug
- DebugStr("\p Attempted to GetViewerFlags without a viewer object.");
- #endif
- theFlags = 0;
- }
-
- return theFlags;
- } // TQD3DViewerView::GetViewerFlags
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::SetCurrentButton:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- void TQD3DViewerView::SetCurrentButton(unsigned long theButton)
- {
- FailOSErr(Q3ViewerSetCurrentButton(fViewer,theButton));
- } // TQD3DViewerView::SetCurrentButton
-
- //----------------------------------------------------------------------------------------
- // TQD3DViewerView::GetCurrentButton:
- //----------------------------------------------------------------------------------------
- #pragma segment ARes
-
- unsigned long TQD3DViewerView::GetCurrentButton()
- {
- unsigned long theButton = 0;
-
- if (fViewer)
- {
- theButton = Q3ViewerGetCurrentButton(fViewer);
- }
- #if qDebug
- else
- {
- DebugStr("\p Attempted to GetCurrentButton without a viewer object.");
- }
- #endif
-
- return theButton;
- } // TQD3DViewerView::GetCurrentButton
-
- //----------------------------------------------------------------------------------------
- // End of UQD3DViewerView.cp
-
- #pragma segment Inline
-